package com.poetic.network.flow.bloom;

/**
 * <pre>
 *  定义一个布隆过滤器
 * Created by lianghuikun on 2020-09-15.
 * </pre>
 *
 * @author lianghuikun
 */
public class Bloom {

    private Integer cap;

    public Bloom() {
    }

    public Bloom(Integer cap) {
        this.cap = cap;
    }

    public Long hash(String value, Integer seed) {
        Long result = 0L;
        for (int i = 0; i < value.length(); i++) {
            // 最简单的 hash 算法，每一位字符的 ascii 码值，乘以 seed 之后，做叠加
            result = result * seed + value.charAt(i);
        }
        return (cap - 1) & result;
    }
}
